package com.cloud.admin.service.impl;

import com.cloud.admin.model.entity.MFilmDetail;
import com.cloud.admin.mapper.MFilmDetailMapper;
import com.cloud.admin.service.MFilmDetailService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 电影详情
 *
 * @author douhaichao code generator
 * @date 2022-09-29 20:14:29
 */
@Service
@AllArgsConstructor
public class MFilmDetailServiceImpl extends ServiceImpl<MFilmDetailMapper, MFilmDetail> implements MFilmDetailService {

    /**
   * 根据对象属性查找满足条件的第一条数据     *      * @return
   */
    @Override
    public MFilmDetail selectOne(MFilmDetail req) {
        QueryWrapper queryWrapper = new QueryWrapper<MFilmDetail>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<MFilmDetail> selectAll(MFilmDetail req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<MFilmDetail> selectPage(Page page, MFilmDetail req) {
        IPage<MFilmDetail> list = baseMapper.selectPage(
                page,
                new QueryWrapper<MFilmDetail>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<MFilmDetail> selectPageByLike(Page page, MFilmDetail req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        
                                        if (null !=req.getId()) {
                    queryWrapper.eq("id" , req.getId());
                }
                    
                                        if (null !=req.getFId()) {
                    queryWrapper.eq("f_id" , req.getFId());
                }
                    
                            if (!StrUtil.isEmpty(req.getZyk())) {
                    queryWrapper.like("zyk" , req.getZyk());
                }
                                
                            if (!StrUtil.isEmpty(req.getZykyun())) {
                    queryWrapper.like("zykyun" , req.getZykyun());
                }
                                        IPage<MFilmDetail> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(MFilmDetail req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }
}
